<template>
  <el-dialog title="预约展示" v-model="isAppoint" width="888px" :before-close="closeAppoint">
    <el-form label-width="120px">
      <div style="margin: 0 20px 10px 100px; height: 100%; float: left">
        <div class="head_selected">
          <div style="display: flex">
            <div style="background-color: #ffa4a4; width: 40px; height: 20px; margin-right: 10px"></div>
            <div class="text">已有预约（{{ dateTime }}）</div>
          </div>
        </div>
        <div style="margin: 10px 50px 0 20px; height: 100%; float: left" class="button_wrap">
          <el-button v-for="(item, index) in timeArr" :key="index"
                     :type="item.status === 0 ? '' : item.status === 1 ? 'danger' : item.status === 2 ? '' : 'primary'"
                     :disabled="item.status === 1" class="button_style">{{ item.showTime }}
          </el-button>
        </div>
      </div>
    </el-form>
    <template v-slot:footer>
      <el-button @click="closeAppoint">取消</el-button>
    </template>
  </el-dialog>
</template>
<script>
import baseService from "@/service/baseService";

export default {
  data() {
    return {
      isAppoint: false,
      dateTime: "",
      timeArr: [] //所有时间
    };
  },
  methods: {
    closeAppoint() {
      this.isAppoint = false;
    },
    showAppoint(dateTime) {
      this.isAppoint = true;
      this.dateTime = dateTime;
      let formData = {
        dateTime: dateTime
      };
      this.getAppointed(formData);
    },
    //时间格式转为年月日
    getYMD(time) {
      let date = new Date(time);
      return date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
    },
    //获取时间数组
    async getAppointed(formData) {
      const res = await baseService.get("/yckj/order/times", {
        dateTime: formData.dateTime
      });
      this.timeArr = res.data;
    }
  }
};
</script>
<style scoped>

.head_selected {
  display: flex;
  font-size: 18px;
  justify-content: space-between;
  margin: 20px 70px 10px 20px;
}

.top_style,
.top_active {
  border: 1px solid #aaa;
  padding: 3px 20px;
  text-align: center;
}

.top_active {
  border-color: #02a7f0;
  color: #02a7f0;
}

.button_style {
  text-align: center;
  float: left;
  width: 98px;
}

.button_wrap .el-button {
  text-align: center;
  float: left;
  margin: 0 10px 10px 0;
}

.text {
  line-height: 20px;
}
</style>
